#include "EPSGLua/LuaEngine.h"

#include "EPSGLua/Global.h"
#include <stdio.h>

bool EPSGLua::LuaEngine::apply( unsigned char key, int x, int y )
{
	TypeEngineCallbackMap::iterator i;
	for( i = _callbackMap.begin(); i != _callbackMap.end(); ++i )
	{
		if( key == i->first )
		{
			std::string cmd = i->second + "()";
			int res = luaL_dostring( EPSGLua::Global::instance()->getLuaState(), cmd.data() );
			if( res == 1 )
				return true;
		}
	}
	return false;
}

void EPSGLua::LuaEngine::registerKey( std::string key, std::string luaFunc )
{
	_callbackMap.insert( TypeEngineCallbackPair( key.at(0), luaFunc ) );
}